﻿using WorkOne.Domain;
using WorkOne.Domain.Model;
using WorkOne.IRepository;

namespace WorkOne.Repository
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        public GoodsDbContext db { get; }

        public BaseRepository(GoodsDbContext db)
        {
            this.db = db;
        }

        public bool Add(T t)
        {
            db.Set<T>().Add(t);
            return db.SaveChanges() > 0;
        }

        public bool Delete(int id)
        {
            db.Set<T>().Find(id);
            return db.SaveChanges() > 0;
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public bool Update(T t)
        {
            db.Set<T>().Update(t);
            return db.SaveChanges() > 0;
        }
    }
}